# -*- coding: utf-8 -*-
# author: AZJ
# date: 2024/11/15
# 假如命运扼住了你的咽喉，你就去挠她的咯吱窝
import time

from selenium.webdriver.common.by import By
from appium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

caps = {
    "platformName": "Android",
    "platformVersion": "7.1.2",
    "deviceName": "127.0.0.1:62001",
    "appPackage": "com.android.Calendar",
    "appActivity": "com.android.Calendar.ui.activity.MainActivity"
}

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

time.sleep(2)
el1 = driver.find_element(By.ID,value="com.android.Calendar:id/btn_skip")
el1.click()
time.sleep(0.5)
el2 = driver.find_element(By.ID,value='com.android.Calendar:id/tv_search')
el2.click()
time.sleep(0.5)
el3 = driver.find_element(By.ID,value='com.android.Calendar:id/et_search_word')
el3.send_keys("原神")
time.sleep(0.3)
el4 = driver.find_element(By.ID,"com.android.Calendar:id/ibtn_search")
el4.click()
time.sleep(0.3)
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/androidx.viewpager.widget.ViewPager/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.ScrollView/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView[1]/android.widget.LinearLayout[1]/android.widget.ImageView")))
el5 = driver.find_element(By.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/androidx.viewpager.widget.ViewPager/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.ScrollView/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView[1]/android.widget.LinearLayout[1]/android.widget.ImageView")
el5.click()
time.sleep(2)


driver.quit()
